#pragma once
#include "LinkFabric.hpp"
#include "StreamBuffer.hpp"

namespace linkfabric {
class Stream {
public:
    Stream(LinkFabric& fabric);
    int open();
    void close(int channelId);
    bool sendStream(int channelId, uint8_t tag, const std::vector<uint8_t>& data, size_t chunkSize = 512);
    void onStream(int channelId, std::function<void(uint8_t tag, const std::vector<uint8_t>&)> callback);
    void run();
private:
    LinkFabric& fabric_;
    std::map<int, StreamBuffer> buffers_;
    std::map<int, std::function<void(uint8_t, std::vector<uint8_t>)>> handlers_;
};
}